// 创建文章集合

// 1、引入mongoose
const mongoose = require('mongoose')
// 2、创建文件集合规则
const articleSchema = new mongoose.Schema({
    title: {
        type: String,
        maxlength: 20,
        minlength: 4,
        // required: true,
        required: [true, '请填写文章标题'], // 带默认值
    },
    // 作者
    author: {
        type: mongoose.Schema.Types.ObjectId,
        ref: 'User', // 和User集合关联
        required: [true, '请传递作者']
    },
    // 发布日期
    publishDate: {
        type: Date,
        default: Date.now,
    },
    // 封面
    cover: {
        type: String,
        default: null,
    },
    content: {
        type: String,
    }
})
// 3、根据规则创建集合
const Article = mongoose.model('Article', articleSchema);
// 4、将集合规则作为模板成员导出
module.exports = {
    Article,
}